package cl.whyem.spring.integration.mail.spring;

import java.util.Date;
import java.util.concurrent.atomic.AtomicBoolean;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;

/**
 * Trigger que se ejecuta una sola vez.
 */
public class OnlyOnceTrigger implements Trigger {

    private final AtomicBoolean invoked = new AtomicBoolean();

    @Override
    public Date nextExecutionTime(TriggerContext triggerContext) {
        return this.invoked.getAndSet(true) ? null : new Date();
    }

}
